package com.example.listview.ListView;


import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.listview.R;

public class mylistAdaptor extends BaseAdapter {


    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public mylistAdaptor(Context context) {
        this.mContext = context;
        mLayoutInflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    public class ViewHolder{
        public ImageView imageview;
        public TextView tvTitle, tvTime, tvContent;
    }
    @Override
    public View getView(int i, View ContextView, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if(ContextView == null) {
            ContextView = mLayoutInflater.inflate(R.layout.layout_list_item, null);
            holder = new ViewHolder();
            holder.imageview = (ImageView) ContextView.findViewById(R.id.iv);
            holder.tvTitle = (TextView) ContextView.findViewById(R.id.tv_title);
            holder.tvTime = (TextView) ContextView.findViewById(R.id.tv_time);
            holder.tvContent = (TextView) ContextView.findViewById(R.id.tv_context);
            ContextView.setTag(holder);
        } else {
            holder = (ViewHolder) ContextView.getTag();
        }

        //给控件赋值
        holder.tvTitle.setText("这是标题");
        holder.tvTime.setText("2022-08-08");
        holder.tvContent.setText("这是内容1");
        return ContextView;
    }
}
